<template>
  <div class="gallery-container" @click="handleGalleryClick">
    <div class="img-wrapper">
      <swiper :options="swiperOptions" v-if="isSwiperShow">
        <!---slides--->
        <swiper-slide v-for="(item, index) in imgsList" :key="index">
          <img
            class="gallery-img"
            :src="item"
          />
        </swiper-slide>
        <!---slides--->
        <div class="swiper-pagination" slot="pagination"></div>
      </swiper>
    </div>
  </div>
</template>

<script>
export default {
  name: "CommonGallery",
  props: {
      // imgsList: Array,
      // default: function() {
      //     return [];
      // }
    //下面这样写也行
    imgsList: {
        type: Array,
        default: function() {
          return [];
        }
      }
  },
  data: function() {
    return {
      swiperOptions: {
        pagination: ".swiper-pagination",
        paginationType: "fraction",
        loop: true,
        observer: true,
        observeParents: true//observer: true,和observeParents: true是为了解决分页器一开始隐藏点击才打开后造成的分页器数量显示0/0的问题
      }
    };
  },
  methods: {
      handleGalleryClick: function() {
          this.$emit('closeGallery');
      }
  },
  computed: {
    isSwiperShow: function() {
      return this.imgsList.length;
    }
  }
};
</script>

<style lang="stylus" scoped>
div {
  display: flex;
}

.gallery-container >>> .swiper-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.gallery-container >>> .swiper-slide {
  flex-direction: column;
  justify-content: center;
}

.gallery-container {
  position: relative;
  position: fixed;
  display: flex;
  flex-direction: column;
  justify-content: center;
  z-index: 99;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #000;
}

.gallery-container .img-wrapper {
  width: 100%;
  height: 0;
  padding-bottom: 100%;
}

.gallery-container .img-wrapper img {
  width: 100%;
}

.gallery-container .img-wrapper .swiper-pagination {
  bottom: 0.48rem;
  justify-content: center;
  color: #fff;
  // font-size: .24rem;
  line-height: 0.8rem;
}
</style>



